package com.itqianfeng.test01;

import java.util.Random;

public class RandomArrays {


    public static void main(String[] args) {
//      1,随机生成指定长度的字符串（字符串内容选择范围为[A-Za-z]）
        String string = specifyString(12);
        System.out.println(string);

//      2、随机生成1-100之间的整数
        int r = intRandm();
        System.out.println(r);


//      3,随机生成性别字符串(male / female)
        String male = maleRandom();
        System.out.println(male);
    }

//    随机生成1-100之间的整数
    public  static  int  intRandm (){
        Random rand = new Random();
        return  rand.nextInt(100) + 1;
    }

//    随机生成性别字符串(male / female)
    public static String maleRandom() {
        if ((int)Math.random() ==0){
            return "male";
        }else{
            return "female";
        }
    }

//  随机生成指定长度的字符串（字符串内容选择范围为[A-Za-z]）
    public static  String specifyString(int l) {
        char[] chars = new char[l];
        Random rand = new Random();
        int r;
        for (int i = 0; i < l; ) {
            r = rand.nextInt(58) + 65;
            if ((r>=65&&r<=90) || (r>=97&&r<=122)){
                chars[i] = (char)r;
                i++;
            }
        }
        return String.valueOf(chars);
    }
}
